﻿using Microsoft.AspNetCore.Authorization;
using System.Linq;
using System.Threading.Tasks;

namespace Batman.IdentityServer.Extension.Handers
{
    /// <summary>
    /// 授权拦截
    /// </summary>
    public class RbacAuthorizationHandler : AuthorizationHandler<RbacRequirement>
    {
        protected override Task HandleRequirementAsync(
            AuthorizationHandlerContext context,
            RbacRequirement requirement)
        {
            var action = ((Microsoft.AspNetCore.Mvc.ActionContext)context.Resource).RouteData.Values["action"].ToString();
            var routeData = ((Microsoft.AspNetCore.Mvc.ActionContext)context.Resource).RouteData.Values;
            var uri = string.Join("_", routeData.ToList().Select(t => t.Value));


            //context.Fail();
            context.Succeed(requirement);
            
            return Task.CompletedTask;
        }
    }
}
